﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Infrastructure;
using MSIACCSL2.Web.WarehouseServices;

namespace MSIACCSL2.Web.ReportPage
{
    public partial class PO : System.Web.UI.Page
    {
        private DataAccess<Object> DA;
        private ReportDocument _po;
        private string Tipe;

        public PO()
        {
            DA = new DataAccess<object>();
            _po = new ReportDocument();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
          if (IsPostBack)
            LoadReport(Request.QueryString["no"].ToString());
        }


        public void LoadReport(string NoBTB)
        {
            string sql = "Select a.PONumber,a.PODate,a.TglTerimaBarang,a.Term,a.Kurs,a.Ppn,a.Description,a.Discount,a.CurrencyCode,a.KodeWarehouse, " +
                       "(Case When a.DiscountType is Null then '' Else a.DiscountType End) as DiscountType " +
                       " ,b.Qty,b.Price,b.Discount as DiscountD,(Case When b.DiscountType is Null then '' Else b.DiscountType End) as DiscountTypeD,s.SubGroupName,c.SupplierName,c.Address,c.ContactPerson,c.Telp,c.Fax     " +
                       " from PurchaseOrder a inner Join PurchaseOrderDetail b on a.PONumber = b.PONumber " +
                       " Left Join Supplier c on c.SupplierId = a.SupplierId " +
                       " Left Join Subgroup s on s.SubgroupId = b.SubgroupId " +
                       " Where a.PONumber='" + NoBTB + "'  Order By s.SubgroupId ";

            var Source = DA.GetDataListDataSet(sql);
            string reportPath = Server.MapPath("~/Report/PurchaseOrder.rpt");
            _po.Load(reportPath);
            _po.SetDataSource(Source.Tables[0]);
            CrystalReportViewer1.ReportSource = _po;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            LoadReport(Request.QueryString["no"].ToString());
        }


        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
            this.Unload += Page_Unload;
        }

        void Page_Unload(object sender, EventArgs e)
        {
            _po.Clone();
            _po.Dispose();

        }
      
    }
}